﻿@model ShoppingCartModel
@using Nop.Web.Models.ShoppingCart;
<div class="order-summary-content">
    @Html.Widget("mobile_order_summary_content_before")
    @Html.Partial("_OrderReviewData", Model.OrderReviewData)
    @if (Model.Items.Count > 0)
    {
        if (Model.Warnings.Count > 0)
        {
        <div class="message-error">
            <ul>
                @for (int i = 0; i < Model.Warnings.Count; i++)
                {
                    <li>@Model.Warnings[i]</li>
                }
            </ul>
        </div>
        }
@*set "data-ajax" attribute to "false"*@
@*we add enctype = "multipart/form-data" because "File upload" attribute control type requries it*@
        using (Html.BeginRouteForm("ShoppingCart", FormMethod.Post,
            new Dictionary<string, Object> { { "data-ajax", "false" }, { "enctype", "multipart/form-data" } }))
        {
        <div class="cart">
            <ul data-role="listview" data-inset="true" data-filter="false" data-theme="c">
                @foreach (var item in Model.Items)
                {
                    <li>
                        <div class="cart-item-row">
                            <div class="product">
                                <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })">@item.ProductName</a>
                                @if (!String.IsNullOrEmpty(item.AttributeInfo))
                                {
                                    <div class="attributes">
                                        @Html.Raw(item.AttributeInfo)
                                    </div>
                                }
                                @if (!String.IsNullOrEmpty(item.RecurringInfo))
                                {
                                    <div class="recurring-info">
                                        @Html.Raw(item.RecurringInfo)
                                    </div>
                                }
                                @if (item.Warnings.Count > 0)
                                {
                                    <div class="message-error">
                                        <ul>
                                            @for (int i = 0; i < item.Warnings.Count; i++)
                                            {
                                                <li>@item.Warnings[i]</li>
                                            }
                                        </ul>
                                    </div>
                                }
                            </div>
                            @if (Model.ShowSku && !String.IsNullOrEmpty(item.Sku))
                            {
                                <div class="sku">
                                    @T("ShoppingCart.SKU"): @item.Sku
                                </div>
                            }
                            <div class="unitprice">
                                @T("ShoppingCart.UnitPrice"): @item.UnitPrice
                            </div>
                            <div class="quantity">
                                @T("ShoppingCart.Quantity"):
                                @if (Model.IsEditable)
                                {
                                    if (item.AllowedQuantities.Count > 0)
                                    {
                                    <select name="itemquantity@(item.Id)" class="qty-dropdown"  data-mini="true" data-inline="true">
                                        @foreach (var qty in item.AllowedQuantities)
                                        {
                                            <option selected="@qty.Selected" value="@qty.Value">@qty.Value</option>
                                        }
                                    </select>
                                    }
                                    else
                                    {
                                    <input name="itemquantity@(item.Id)" type="text" value="@(item.Quantity)" class="qty-input" />
                                    }
                                }
                                else
                                {
                                    <span>@item.Quantity</span>
                                }
                            </div>
                            <div class="totalprice">
                                @T("ShoppingCart.ItemTotal"): @item.SubTotal
                                @if (!String.IsNullOrEmpty(item.Discount))
                                {
                                    <div class="discount">
                                        @T("ShoppingCart.ItemYouSave"): @item.Discount
                                    </div>
                                }
                            </div>
                            @if (Model.IsEditable)
                            {
                                <div class="updateitem">
                                    <input type="submit" name="updatecartitem-@(item.Id)" value="@T("ShoppingCart.UpdateCartItem")" />
                                </div>
                                <div class="remove">
                                    <input type="submit" name="removefromcart-@(item.Id)" value="@T("ShoppingCart.Remove")" />
                                </div> 
                            }
                        </div>
                    </li>
                }
            </ul>
        </div>
                if (!String.IsNullOrEmpty(Model.CheckoutAttributeInfo))
                {
        <div class="selected-checkout-attributes">
            @Html.Raw(Model.CheckoutAttributeInfo)
        </div>
                }
        <div>
            @if (Model.IsEditable)
            {
                <div class="common-buttons">
                    <input type="submit" name="continueshopping" value="@T("ShoppingCart.ContinueShopping")" />

                </div>
                @Html.Partial("_CheckoutAttributes", Model.CheckoutAttributes, new ViewDataDictionary())
            }
        </div>
        <div class="cart-footer">
            @if (Model.IsEditable)
            {
                if (!String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                {
                <div>
                    <div class="min-amount-warning">
                        @Model.MinOrderSubtotalWarning
                    </div>
                </div>
                }
            }
            <div class="cart-collaterals">
                @if (Model.IsEditable)
                {
                    <div class="deals">
                        @Html.Partial("_DiscountBox", Model.DiscountBox)
                        @Html.Partial("_GiftCardBox", Model.GiftCardBox)
                        @Html.Widget("mobile_order_summary_content_deals")
                    </div>
                }
            </div>
            <div class="totals">
                @Html.Action("OrderTotals", "ShoppingCart", new { isEditable = Model.IsEditable })
                @if (Model.IsEditable)
                {
                    if (Model.TermsOfServiceOnShoppingCartPage)
                    {
                    <div class="terms-of-service">
                        <input id="termsofservice" type="checkbox" name="termsofservice" />
                        <label for="termsofservice">@T("Checkout.TermsOfService.IAccept")</label>
                    </div>
                    }
                    <div class="checkout-buttons">
                        @if (String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                        {
                            <script type="text/javascript">
                                $(document).ready(function () {
                                    $('#checkout').click(function () {

                                        //terms of service
                                        var termOfServiceOk = true;
                                        if ($('#termsofservice').length > 0) {
                                            //terms of service element exists
                                            if (!$('#termsofservice').is(':checked')) {
                                                alert('@Html.Raw(HttpUtility.JavaScriptStringEncode(T("Checkout.TermsOfService.PleaseAccept").Text))');
                                                termOfServiceOk = false;
                                            } else {
                                                termOfServiceOk = true;
                                            }
                                        }
                                        return termOfServiceOk;
                                    });
                                });
                            </script>
                            <button type="submit"  id="checkout" name="checkout" value="checkout">@T("Checkout.Button")</button>
                        }
                    </div>
                    <div class="addon-buttons">
                        @*Payment method buttons (e.g. GoogleCheckoutButton, Paypal Express)*@
                        @Html.Partial("_ButtonPaymentMethod", Model)
                    </div>
                }
            </div>
        </div>
        }
    }
    else
    {
        @T("ShoppingCart.CartIsEmpty")
    }
    @Html.Widget("mobile_order_summary_content_after")
</div>
